const mongoose = require("mongoose");
const { infosModel } = require("../models/infosModel");
//得到全部数据
async function getInfos(req, res) {
    let data = await mongoose.model(infosModel).find()
    res.send({
        message: "响应成功",
        code: 200,
        data
    })
}
//通过id得到数据
async function getIdInfo(req, res) {
    let data = await mongoose.model(infosModel).find(req.params);
    await mongoose.model(infosModel).updateOne(req.params, { type: "" });
    res.send({
        message: "响应成功",
        code: 200,
        data
    })
}
//通过类型的到数据
async function getTypeInfo(req, res) {
    switch (req.body.type) {
        case "0":
            let data1 = await mongoose.model(infosModel).find();
            senddata(data1)
            break;
        case "1":
            let data2 = await mongoose.model(infosModel).find({type:""});
            senddata(data2)
            break;
        case "2":
            let data3 = await mongoose.model(infosModel).find({ type: "【未读】" });
            senddata(data3)
            break;
    }
    function senddata(data){
        res.send({
            message: "响应成功",
            code: 200,
            data
        })
    }
}
module.exports = {
    getInfos,
    getIdInfo,
    getTypeInfo
}